﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FirstGame
{
    public class ScreenManager
    {
        List<GameScreen> _Screens;

        public List<GameScreen> Screens
        {
            get { return _Screens; }
            set { _Screens = value; }
        }

        private IntroScreen _Introscreen;

        public IntroScreen Introscreen
        {
            get { return _Introscreen; }
            set { _Introscreen = value; }
        }

        private MainMenuScreen _Mainmenuscreen;

        public MainMenuScreen Mainmenuscreen
        {
            get { return _Mainmenuscreen; }
            set { _Mainmenuscreen = value; }
        }
        
        InputSystem _Input;

        public InputSystem Input
        {
            get { return _Input; }
            set { _Input = value; }
        }

        
        public ScreenManager(ContentManager content)
        {
            Screens = new List<GameScreen>();
            Input = new InputSystem();
             _Introscreen= new IntroScreen(content, "BackgroundTexture\\background4", Vector2.Zero);
             _Introscreen.Exited += new EventHandler(_Introscreen_Exited);
             Screens.Add(_Introscreen);

             string[] strTextures0 = { "TextureMenuItems\\bt_newgame", "TextureMenuItems\\bt_loadgame", "TextureMenuItems\\bt_setting", "TextureMenuItems\\bt_help", "TextureMenuItems\\bt_exit" };
             string[] strTextures1 = { "TextureMenuItems\\bt_newgame_selection", "TextureMenuItems\\bt_loadgame_selection", "TextureMenuItems\\bt_setting_selection", "TextureMenuItems\\bt_help_selection", "TextureMenuItems\\bt_exit_selection" };
            _Mainmenuscreen = new MainMenuScreen(content, this, "BackgroundTexture\\background", strTextures0, strTextures1, new Vector2(20, 150));


            _Mainmenuscreen.ScreenState = ScreenState.InActive;
            _Mainmenuscreen.TransitionOnTime = TimeSpan.FromSeconds(2);
            _Mainmenuscreen.TransitionOffTime = TimeSpan.FromSeconds(2);
            Screens.Add(_Mainmenuscreen);

           
            


        }

        void _Introscreen_Exited(object sender, EventArgs e)
        {
            _Mainmenuscreen.Active();
        }


        public void Update(GameTime gameTime)
        {
            Input.Update();
            //Introscreen.Update(gameTime, _Input);
            
            foreach (GameScreen screen in Screens)
            {
                if (screen.ScreenState != ScreenState.InActive)
                    screen.Update(gameTime, Input);
            }
            
             
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (GameScreen screen in Screens)
            {
                if (screen.ScreenState != ScreenState.InActive)
                    screen.Draw(gameTime, spriteBatch);
            }
           
        }
    }
}
